﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using KPIS.GERP.ESS.APP.App_UI.Commons;
using KPIS.GERP.ESS.BLL;
using KPIS.GERP.ESS.MODEL;

namespace KPIS.GERP.ESS.APP.App_UI.UserControls
{
    public partial class DropDownList_Emp : System.Web.UI.UserControl
    {
        public RadComboBox Child;
        int nOffset = 10;
        Main main = new Main();
        FIM_Employees.FIM_Employees emp = new FIM_Employees.FIM_Employees();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        public RadComboBox GetComboBox()
        {
            RadComboBox ddl = ddlEmpSeq;
            return ddl;
        }

        public void LoadData(RadComboBoxItemsRequestedEventArgs e)
        {
            string strFilter = e.Text;
            string strEmpTypeSeq = (lblEmpTypeSeq.Text.Length > 0 ? lblEmpTypeSeq.Text : null);
            string strJobsiteSeq = (lblJobsiteSeq.Text.Length > 0 ? lblJobsiteSeq.Text : null);
            string strWorkingJobsiteSeq = (lblWorkingJobsiteSeq.Text.Length > 0 ? lblWorkingJobsiteSeq.Text : null);
            IList<FIM_Employees.M_HRM_PS_Employees> infolist = emp.GetList(strEmpTypeSeq, strJobsiteSeq, strWorkingJobsiteSeq, strFilter);
            int itemOffset = e.NumberOfItems;
            int endOffset = Math.Min(itemOffset + nOffset, infolist.Count);
            e.EndOfItems = endOffset == infolist.Count;

            for (int i = itemOffset; i < endOffset; i++)
            {
                ddlEmpSeq.Items.Add(new RadComboBoxItem(infolist[i].emp_name, infolist[i].emp_seq.ToString()));
            }

            e.Message = main.GetStatusMessage(endOffset, infolist.Count);
        }

        public void LoadControl(Nullable<int> nWidth, Nullable<int> nSetOffset
            , string strEmpTypeSeq, string strJobSiteSeq, string strWorkingJobSiteSeq)
        {
            if (nWidth != null)
                ddlEmpSeq.Width = Unit.Pixel(nWidth.Value);

            if (nSetOffset != null)
                nOffset = nSetOffset.Value;

            lblEmpTypeSeq.Text = strEmpTypeSeq;
            lblJobsiteSeq.Text = strJobSiteSeq;
            lblWorkingJobsiteSeq.Text = strWorkingJobSiteSeq;
        }

        public void SetSelectedValue(string strValue)
        {
            if (strValue.Length > 0)
            {
                lblEmpSeq.Text = strValue;

                if (ddlEmpSeq.FindItemByValue(strValue) == null)
                {
                    FIM_Employees.M_HRM_PS_Employees info = emp.GetInfo(strValue);
                    ddlEmpSeq.Text = info.emp_name;
                }
                else
                {
                    ddlEmpSeq.SelectedValue = strValue;
                }
            }
            else
            {
                ddlEmpSeq.SelectedIndex = -1;
                ddlEmpSeq.Text = "";
                lblEmpSeq.Text = "";
            }
        }

        public string GetSelectedValue()
        {
            string strValue = lblEmpSeq.Text;

            return strValue;
        }

        public void SelectedIndexChanged(string strValue)
        {
            lblEmpSeq.Text = strValue;

            switch (Page.ToString())
            {
                case "ASP.app_ui_forms_ess_project_aspx":
                    Label lblEmpPosName = (Label)this.Parent.FindControl("lblEmpPosName");
                    Label lblJobsiteName = (Label)this.Parent.FindControl("lblJobsiteName");
                    Label lblClassName = (Label)this.Parent.FindControl("lblClassName");

                    if (strValue.Length > 0)
                    {
                        FIM_Employees.M_HRM_PS_Employees info = emp.GetInfo(strValue);
                        lblEmpPosName.Text = info.pos_name;
                        lblJobsiteName.Text = info.working_job_site_name;
                        lblClassName.Text = info.class_name;
                    }
                    else
                    {
                        lblEmpPosName.Text = "";
                        lblJobsiteName.Text = "";
                        lblClassName.Text = "";
                    }
                    break;
                case "ASP.app_ui_forms_ess_moneyreturns_aspx":
                    Label lblEmpPosName2 = (Label)this.Parent.FindControl("lblEmpPosName");
                    Label lblJobsiteName2 = (Label)this.Parent.FindControl("lblJobsiteName");

                    if (strValue.Length > 0)
                    {
                        FIM_Employees.M_HRM_PS_Employees info = emp.GetInfo(strValue);
                        lblEmpPosName2.Text = info.pos_name;
                        lblJobsiteName2.Text = info.working_job_site_name;
                    }
                    else
                    {
                        lblEmpPosName2.Text = "";
                        lblJobsiteName2.Text = "";
                    }
                    break;
                case "ASP.app_ui_forms_ess_moneyrequests_aspx" :
                    if (UniqueID == "ctl00$ContentPlaceHolder1$DropDownList_Emp2")
                    {
                        Label lblPosSeq3 = (Label)this.Parent.FindControl("lblPosSeq");
                        Label lblJobsiteSeq3 = (Label)this.Parent.FindControl("lblJobsiteSeq");
                        Label lblClassSeq3 = (Label)this.Parent.FindControl("lblClassSeq");
                        Label lblOldClassSeq3 = (Label)this.Parent.FindControl("lblOldClassSeq");
                        Label lblPosName3 = (Label)this.Parent.FindControl("lblPosName");
                        Label lblJobsiteName3 = (Label)this.Parent.FindControl("lblJobsiteName");
                        Label lblClassName3 = (Label)this.Parent.FindControl("lblClassName");
                        Label lblOldClassName3 = (Label)this.Parent.FindControl("lblOldClassName");
                        LinkButton cmdInsert3 = (LinkButton)this.Parent.FindControl("cmdInsert1");
                        LinkButton cmdUpdate3 = (LinkButton)this.Parent.FindControl("cmdUpdate1");

                        if (strValue.Length > 0)
                        {
                            FIM_Employees.M_HRM_PS_Employees info = emp.GetInfo(strValue);
                            lblPosSeq3.Text = info.pos_seq.ToString();
                            lblJobsiteSeq3.Text = info.job_site_seq.ToString();
                            lblClassSeq3.Text = info.class_seq.ToString();
                            lblOldClassSeq3.Text = info.old_class_seq.ToString();
                            lblPosName3.Text = info.pos_name;
                            lblJobsiteName3.Text = info.working_job_site_name;
                            lblClassName3.Text = info.class_name;
                            lblOldClassName3.Text = info.old_class_name;
                        }
                        else
                        {
                            lblPosSeq3.Text = "";
                            lblJobsiteSeq3.Text = "";
                            lblClassSeq3.Text = "";
                            lblOldClassSeq3.Text = "";
                            lblPosName3.Text = "";
                            lblJobsiteName3.Text = "";
                            lblClassName3.Text = "";
                            lblOldClassName3.Text = "";
                        }

                        if (cmdInsert3.Visible)
                        {
                            cmdInsert3.Focus();
                        }
                        else
                        {
                            cmdUpdate3.Focus();
                        }
                    }
                    break;
            }
        }

        protected void ddlEmpSeq_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            SelectedIndexChanged(ddlEmpSeq.SelectedValue);
        }

        protected void ddlEmpSeq_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadData(e);
        }
    }
}